unit uConfig;

interface

function ReadIni(group, name, defaultvalue: String): String; overload;
function ReadIni(group, name: String; defaultvalue: Integer): Integer; overload;
function ReadIni(group, name: String; defaultvalue: Boolean): Boolean; overload;

const
	IniFileName = 'auto_tester.cfg';

implementation

uses
	Windows,
	StrUtils,
	SysUtils;

function ReadIni(group, name, defaultvalue: String): String;
const
	MaxSize = 260;
var
	buff: array[0..MaxSize] of Char;
	//size: Integer;
begin
	{size := }GetPrivateProfileString(PChar(group), PChar(name), PChar(defaultvalue), buff, MaxSize, PChar(IniFileName));
	result := StrPas(buff);
end;

function ReadIni(group, name: String; defaultvalue: Integer): Integer;
var
	S: String;
	Code: Integer;
begin
	S := ReadIni(group, name, '');
	Val(S, result, Code);
	if (Code <> 0) then
		result := defaultvalue;
end;

function ReadIni(group, name: String; defaultvalue: Boolean): Boolean;
var
	S: String;
	Code: Integer;
	iRet: Integer;
begin
	S := UpperCase( ReadIni(group, name, '') );
	if (S = 'TRUE') then
	begin
		result := True;
		exit;
	end
	else if (S = 'FALSE') then
			 begin
				 result := False;
				 exit;
			 end;
			 
	Val(S, iRet, Code);
	if (Code <> 0) then
		result := defaultvalue
	else
		result := (iRet > 0);
end;

end.
